<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>res_edit.html</title>
</head>
 <body>
 <script type="text/javascript">
 	var winUnitList = new Windows("user_unit");
 	$(function(){
 		var isFirstLoad = true;
 		$("#unitTree").tree({
 			url:'$!basePath/admin/unit/unitListForUser',
 			animate:true,
 			onLoadSuccess:function(node,data){
 				if(!isFirstLoad){
 					var selectedUnit = winUnitList.getParam();
 					var unitTree = winUnitList.find("#unitTree");
	 				if(selectedUnit.length>0){
		 				var node = unitTree.tree("find",selectedUnit);
		 				unitTree.tree("select",node.target);
	 				}else{
	 					var rootNodes = winUnitList.find("#unitTree").tree("getRoots");
	 					for(var i= 0;i<rootNodes.length;i++){
	 						var rootNode = rootNodes[i];
	 						if(rootNode.text == "$!defaultUnit"){
	 							unitTree.tree("select",rootNode.target);
	 							break;
	 						}else{
	 							var childNodes = unitTree.tree("getChildren",rootNode.target);
	 							for(var j=0;j<childNodes.length;j++){
	 								var childNode = childNodes[j];
	 								if(childNode.text == "$!defaultUnit"){
	 									unitTree.tree("select",childNode.target);
	 								}
	 							}
	 						}
	 					}
	 				}
 				}else{
 					isFirstLoad = false;
 				}
 			}
 		});
 	});
	function winUserUnit_ok(){
		var selectNode = winUnitList.find("#unitTree").tree("getSelected");
		if(selectNode){
			var selectUnit = new JSONObject();
			selectUnit.put("id", selectNode.id);
			selectUnit.put("name",selectNode.text);
			winUnitList.setReturnValue(selectUnit);
			winUnitList.close();
		}else{
			top.Dialog.confirm("提示","您没有选择机构，是否使用默认机构?",function(r){
				if(r){
					winUnitList.setReturnValue("default");
					winUnitList.close();
				}
			});
		}
  	}
  	function winUserUnit_cancel(){
  		winUnitList.setReturnValue("false");
  		winUnitList.close();
  	}
 </script>
 <div class="easyui-layout" data-options="fit:true">
	 <div data-options="region:'center',border:false" style="background:#fff;">
	 	<form id="resForm" method="post" style="padding-left:20px;padding-top:5px;padding-right:20px;">
	 		<ul id="unitTree" class="easyui-tree"></ul>
		</form>
	 </div>
	 <!--Change Button Text-->
	 <div data-options="region:'south',border:false" style="text-align:center;padding:5px 0;">
		<a id="ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="winUserUnit_ok()">确定</a>
		<a id="cancel" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="winUserUnit_cancel()">取消</a>
	</div>
 </div>
  </body>
</html>